package frobagroup.controller.backstage;


import frobagroup.services.backstage.StaffCarouselFigureService;
import frobagroup.utils.Constants;
import frobagroup.utils.ResponseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by Tinsley on 2017/6/19.
 */
@RequestMapping("/webAPI/Carousel/staff")
@RestController
public class StaffCarouselFigureController {

    @Autowired
    private StaffCarouselFigureService staffCarouselFigureService;

    @RequestMapping(value = "/addOrEditCarousel", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> addOrEditCarousel(@RequestParam(value = "pic", required = false) MultipartFile pic,
                                                                   HttpServletRequest request,
                                                                   @RequestParam(value = "pId", required = false) String pId,
                                                                   @RequestParam(value = "cId", required = false) String cId,
                                                                   @RequestParam(value = "describe", required = false) String describe,
                                                                   @RequestParam(value = "whichType", required = false) String whichType,
                                                                   @RequestParam(value = "type", required = false) String type
    ) throws Exception{
        return ResponseModel.success(staffCarouselFigureService.addOrEditCarousel(pic,(String)request.getAttribute("staffId"),
                pId,cId,describe,whichType,type),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/findCarousels", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> findCarousels(@RequestBody Map<String,String> params) throws Exception{
        return ResponseModel.success(staffCarouselFigureService.findCarousels(params),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/changeStatus", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> changeStatus(@RequestParam(value = "cId", required = false) String cId,
                                                              @RequestParam(value = "status", required = false) String status,
                                                              HttpServletRequest request) throws Exception{
        return ResponseModel.success(staffCarouselFigureService.changeStatus(cId,status,(String)request.getAttribute("staffId")),
                Constants.RESPONSE_STATUS_SUCESS);
    }

    @RequestMapping(value = "/remove", method = RequestMethod.POST )
    public ResponseEntity<ResponseModel<Object>> remove(@RequestBody Map<String,String> params) throws Exception{
        staffCarouselFigureService.remove(params.get("id"),params.get("picUrl"));
        return ResponseModel.success(null,
                Constants.RESPONSE_STATUS_SUCESS);
    }

}
